<?php 
 include_once dirname(__FILE__)."/config.php";
 class mail_type_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_id;
		 protected $_sujet;
		 protected $_mail;
		 protected $_descritpion;
		 protected $_id_phase_desc;
		 public function get_name_table(){ return "mail_type";}
		 public function get_name_id(){ return "id";}
		 public function get_name_sujet(){ return "sujet";}
		 public function get_name_mail(){ return "mail";}
		 public function get_name_descritpion(){ return "descritpion";}
		 public function get_name_id_phase_desc(){ return "id_phase_desc";}
		 public function set_id($parametre){  $this->_id=$parametre;}	
		 public function set_sujet($parametre){  $this->_sujet=$parametre;}	
		 public function set_mail($parametre){  $this->_mail=$parametre;}	
		 public function set_descritpion($parametre){  $this->_descritpion=$parametre;}	
		 public function set_id_phase_desc($parametre){  $this->_id_phase_desc=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_id(){ return $this->_id;}
		 public function get_sujet(){ return $this->_sujet;}
		 public function get_mail(){ return $this->_mail;}
		 public function get_descritpion(){ return $this->_descritpion;}
		 public function get_id_phase_desc(){ return $this->_id_phase_desc;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 mail_type(
			sujet,
			mail,
			descritpion,
			id_phase_desc)
 VALUES(
			'".$this->_sujet."',
			'".$this->_mail."',
			'".$this->_descritpion."',
			'".$this->_id_phase_desc."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_sujet)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
sujet='".$this->_sujet."'";
}
if(!empty($this->_mail)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
mail='".$this->_mail."'";
}
if(!empty($this->_descritpion)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
descritpion='".$this->_descritpion."'";
}
if(!empty($this->_id_phase_desc)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_phase_desc='".$this->_id_phase_desc."'";
}
$sql="UPDATE 
mail_type SET 
 ".$sql."
								WHERE id ='".$this->_id."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
mail_type 
 
									WHERE id ='".$this->_id."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
mail_type ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		id,
		sujet,
		mail,
		descritpion,
		id_phase_desc
 FROM 
 mail_type";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_id=$row->id;
		$this->_sujet=$row->sujet;
		$this->_mail=$row->mail;
		$this->_descritpion=$row->descritpion;
		$this->_id_phase_desc=$row->id_phase_desc;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>